#include "recboxitem.h"
#include "ui_recboxitem.h"
#include<QDebug>
#include<QPropertyAnimation>

RecBoxItem::RecBoxItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RecBoxItem)
{
    ui->setupUi(this);
    //事件拦截器
    ui->musicImageBox->installEventFilter(this);
}

RecBoxItem::~RecBoxItem()
{
    delete ui;
}
bool RecBoxItem::eventFilter(QObject *watched, QEvent *event)
{
    if(watched==ui->musicImageBox)
    {
        int ImgWidget=ui->musicImageBox->width();
        int ImgHeight=ui->musicImageBox->height();
        //当鼠标到达页面时
        if( QEvent::Enter==event->type() )
        {
            QPropertyAnimation *animation=new QPropertyAnimation(ui->musicImageBox,"geometry");
            animation->setDuration(150);
            animation->setStartValue(QRect(9,10,ImgWidget,ImgHeight));
            animation->setEndValue(QRect(9, 0, ImgWidget, ImgHeight));
            animation->start();
            //释放QPropertyAnimation对象
            connect(animation, &QPropertyAnimation::finished, this, [=](){
                 delete animation;
             });
             return true;
        }
        else if(QEvent::Leave == event->type())
        {
            QPropertyAnimation *animation=new QPropertyAnimation(ui->musicImageBox,"geometry");
            animation->setDuration(150);
            animation->setStartValue(QRect(9,0,ImgWidget,ImgHeight));
            animation->setEndValue(QRect(9, 10, ImgWidget, ImgHeight));
            animation->start();
            //释放QPropertyAnimation对象
            connect(animation, &QPropertyAnimation::finished, this, [=](){
                 delete animation;
             });
             return true;
        }
        return true;
    }
    return QObject::eventFilter(watched, event);
}
//设置推荐页文本
void RecBoxItem::setRecText(const QString &text)
{
    ui->recBoxItemText->setText(text);
}
//设置推荐页照片
void RecBoxItem::setRecImage(const QString &Imagepath)
{
    QString imgstyle="border-image:url("+Imagepath+");";
    ui->recMusicImage->setStyleSheet(imgstyle);

}
